package com.leetcode_Onequestion;

import java.util.Arrays;

/**
 * @Author jsh
 * @Date 2023/3/13 21:49
 * @Version 1.0
 */
public class leetcode_2383 {

    /*
    * 94
70
[58,47,100,71,47,6,92,82,35,16,50,15,42,5,2,45,22]
[77,83,99,76,75,66,58,84,44,98,70,41,48,7,10,61,28]
    * */
    public static void main(String[] args) {
        int[] energy = {58,47,100,71,47,6,92,82,35,16,50,15,42,5,2,45,22};
        int[] experience = {77,83,99,76,75,66,58,84,44,98,70,41,48,7,10,61,28};

        System.out.println(minNumberOfHours(94, 70, energy, experience));
    }
    public static int minNumberOfHours(int initialEnergy, int initialExperience, int[] energy, int[] experience) {
        int sum = 0;
        for (int en : energy){
            sum += en;
        }
        int enhours = 0;

        if (initialEnergy < sum){
            enhours = sum -initialEnergy +1;
        }else if (initialEnergy == sum){
            enhours = 1;
        }

        int exhour = 0;
        for(int ex : experience){
            if (ex > initialExperience){
                exhour += ex - initialExperience +1;
                initialExperience = 2*ex + 1;

            }else if ( ex == initialExperience){
                exhour += 1;
                initialExperience += ex + 1;
            }else{
                initialExperience += ex;
            }

        }



        return exhour + enhours ;
    }
}
